package com.lancoo.cvas.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lancoo.cvas.entity.*;
import com.lancoo.cvas.mapper.*;
import com.lancoo.cvas.pojo.common.Deleted;
import com.lancoo.cvas.service.ParameterSettingService;
import com.lancoo.cvas.service.TeachingClassService;
import com.lancoo.cvas.service.TeachingClassTeacherService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class ParameterSettingServiceImpl extends ServiceImpl<ParameterSettingMapper, ParameterSetting> implements ParameterSettingService {


    @Resource
    private TeachingClassMapper teachingClassMapper;
    @Resource
    private TeachingClassWeekMapper teachingClassWeekMapper;
    @Resource
    private TeachingClassTeacherMapper teachingClassTeacherMapper;
    @Resource
    private ParameterSettingMapper parameterSettingMapper;
    @Resource
    private ParameterSettingService parameterSettingService;

    @Resource
    private TeachingClassService teachingClassService;
    @Resource
    private TeachingClassTeacherService teachingClassTeacherService;
    @Resource
    private TeacherMapper teacherMapper;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public String modifyIsEnable(Integer taskId, String gradeId, Long courseId, Integer flag, Integer isEnable) {
        if (flag == 1) {
            //课程
            if (isEnable == 0 || isEnable == 6) {
                List<TeachingClass> teachingClassList = teachingClassMapper.selectList(new LambdaQueryWrapper<TeachingClass>()
                        .eq(TeachingClass::getTaskId, taskId).eq(TeachingClass::getGradeId, gradeId)
                        .eq(TeachingClass::getCourseId, courseId).eq(TeachingClass::getFlag, 1)
                        .isNull(TeachingClass::getUniqueShiftSign).eq(TeachingClass::getDeleted, Deleted.NOT.getCode()));

                List<Long> collect = teachingClassList.stream().map(TeachingClass::getTeachingClassId).distinct().collect(Collectors.toList());


                List<TeachingClassWeek> teachingClassWeekList = teachingClassWeekMapper.selectList(new LambdaQueryWrapper<TeachingClassWeek>()
                        .in(TeachingClassWeek::getTeachingClassId, collect)
                        .eq(TeachingClassWeek::getDeleted, Deleted.NOT.getCode()));

                List<TeachingClassTeacher> teachingClassTeacherList = teachingClassTeacherMapper.selectList(new LambdaQueryWrapper<TeachingClassTeacher>()
                        .in(TeachingClassTeacher::getTeachingClassId, collect)
                        .eq(TeachingClassTeacher::getDeleted, Deleted.NOT.getCode()));

                List<ParameterSetting> parameterSettingList = parameterSettingMapper.selectList(new LambdaQueryWrapper<ParameterSetting>()
                        .eq(ParameterSetting::getTaskId, taskId)
                        .eq(ParameterSetting::getGradeId, gradeId)
                        .eq(ParameterSetting::getCourseId, courseId)
                        .eq(ParameterSetting::getFlag, 1)
                        .eq(ParameterSetting::getDeleted, Deleted.NOT.getCode()));

                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .eq(TeachingClass::getTaskId, taskId)
                        .eq(TeachingClass::getGradeId, gradeId)
                        .eq(TeachingClass::getCourseId, courseId)
                        .isNull(TeachingClass::getUniqueShiftSign)
                        .eq(TeachingClass::getFlag, 1)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getState, 0));

                parameterSettingMapper.update(null, new LambdaUpdateWrapper<ParameterSetting>()
                        .eq(ParameterSetting::getTaskId, taskId)
                        .eq(ParameterSetting::getGradeId, gradeId)
                        .eq(ParameterSetting::getCourseId, courseId)
                        .eq(ParameterSetting::getFlag, 1)
                        .eq(ParameterSetting::getDeleted, Deleted.NOT.getCode())
                        .set(ParameterSetting::getState, 0));

                List<Long> parameterSettingId = new ArrayList<>();
                parameterSettingList.forEach(o -> {
                    if (ObjUtil.isNull(o.getRoomType())) {
                        parameterSettingId.add(o.getId());
                    }

                    if (ObjUtil.isNull(o.getTeacherId())) {
                        parameterSettingId.add(o.getId());
                    }
                });
                List<ParameterSetting> collect3 = parameterSettingList.stream().filter(p -> !parameterSettingId.contains(p.getId())).collect(Collectors.toList());

                if (CollUtil.isNotEmpty(collect3)) {
                    collect3.forEach(o -> {
                        o.setState(1);
                    });
                    parameterSettingService.saveOrUpdateBatch(collect3);
                }

                List<Long> teachingClassIds = new ArrayList<>();
                teachingClassList.forEach(o -> {
                    List<TeachingClassWeek> collect1 = teachingClassWeekList.stream().filter(p -> p.getTeachingClassId().equals(o.getTeachingClassId()) && ObjUtil.isNull(p.getRoomType())).collect(Collectors.toList());
                    if (CollUtil.isNotEmpty(collect1)) {
                        teachingClassIds.add(o.getTeachingClassId());
                    }

                    List<Integer> hourType = teachingClassWeekList.stream().filter(p -> o.getTeachingClassId().equals(o.getTeachingClassId()))
                            .map(TeachingClassWeek::getHourType).distinct().collect(Collectors.toList());

                    List<TeachingClassTeacher> teachingClassTeachers = teachingClassTeacherList.stream().filter(p -> p.getTeachingClassId()
                            .equals(o.getTeachingClassId())).collect(Collectors.toList());


                    if (CollUtil.isNotEmpty(teachingClassTeachers)) {
                        Map<Integer, List<TeachingClassTeacher>> collect2 = teachingClassTeachers.stream().collect(Collectors.groupingBy(TeachingClassTeacher::getTeacherType));

                        if (collect2.size() != hourType.size()) {
                            teachingClassIds.add(o.getTeachingClassId());
                        }
                    } else {
                        teachingClassIds.add(o.getTeachingClassId());
                    }
                });

                List<TeachingClass> collect1 = teachingClassList.stream().filter(p -> !teachingClassIds.contains(p.getTeachingClassId())).collect(Collectors.toList());

                if (CollUtil.isNotEmpty(collect1)) {
                    collect1.forEach(o -> {
                        o.setState(1);
                    });
                    teachingClassService.saveOrUpdateBatch(collect1);
                }

                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .eq(TeachingClass::getTaskId, taskId)
                        .eq(TeachingClass::getGradeId, gradeId)
                        .eq(TeachingClass::getCourseId, courseId)
                        .isNull(TeachingClass::getUniqueShiftSign)
                        .eq(TeachingClass::getFlag, 1)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getIsEnable, isEnable));

                parameterSettingMapper.update(null, new LambdaUpdateWrapper<ParameterSetting>()
                        .eq(ParameterSetting::getTaskId, taskId)
                        .eq(ParameterSetting::getGradeId, gradeId)
                        .eq(ParameterSetting::getCourseId, courseId)
                        .eq(ParameterSetting::getFlag, 1)
                        .eq(ParameterSetting::getDeleted, Deleted.NOT.getCode())
                        .set(ParameterSetting::getIsEnable, isEnable));

            } else {
                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .eq(TeachingClass::getTaskId, taskId)
                        .eq(TeachingClass::getGradeId, gradeId)
                        .eq(TeachingClass::getCourseId, courseId)
                        .eq(TeachingClass::getFlag, 1)
                        .isNull(TeachingClass::getUniqueShiftSign)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getState, 1)
                        .set(TeachingClass::getIsEnable, isEnable));

                parameterSettingMapper.update(null, new LambdaUpdateWrapper<ParameterSetting>()
                        .eq(ParameterSetting::getTaskId, taskId)
                        .eq(ParameterSetting::getGradeId, gradeId)
                        .eq(ParameterSetting::getCourseId, courseId)
                        .eq(ParameterSetting::getFlag, 1)
                        .eq(ParameterSetting::getDeleted, Deleted.NOT.getCode())
                        .set(ParameterSetting::getState, 1)
                        .set(ParameterSetting::getIsEnable, isEnable));
            }
        } else {
            //环节
            if (isEnable == 0) {
                List<TeachingClass> teachingClassList = teachingClassMapper.selectList(new LambdaQueryWrapper<TeachingClass>()
                        .eq(TeachingClass::getTaskId, taskId).eq(TeachingClass::getGradeId, gradeId)
                        .eq(TeachingClass::getCourseId, courseId).eq(TeachingClass::getFlag, 2)
                        .isNull(TeachingClass::getUniqueShiftSign)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode()));

                List<Long> collect = teachingClassList.stream().map(TeachingClass::getTeachingClassId).distinct().collect(Collectors.toList());



                List<TeachingClassTeacher> teachingClassTeacherList = teachingClassTeacherMapper.selectList(new LambdaQueryWrapper<TeachingClassTeacher>()
                        .in(TeachingClassTeacher::getTeachingClassId, collect)
                        .eq(TeachingClassTeacher::getDeleted, Deleted.NOT.getCode()));

                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .eq(TeachingClass::getTaskId, taskId)
                        .eq(TeachingClass::getGradeId, gradeId)
                        .eq(TeachingClass::getCourseId, courseId)
                        .eq(TeachingClass::getFlag, 2)
                        .isNull(TeachingClass::getUniqueShiftSign)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getState, 0));

                parameterSettingMapper.update(null, new LambdaUpdateWrapper<ParameterSetting>()
                        .eq(ParameterSetting::getTaskId, taskId)
                        .eq(ParameterSetting::getGradeId, gradeId)
                        .eq(ParameterSetting::getCourseId, courseId)
                        .eq(ParameterSetting::getFlag, 2)
                        .eq(ParameterSetting::getDeleted, Deleted.NOT.getCode())
                        .set(ParameterSetting::getState, 0));

                List<Long> teachingClassIds = new ArrayList<>();
                teachingClassList.forEach(o -> {

                    if (CollUtil.isNotEmpty(teachingClassTeacherList)) {

                    } else {
                        teachingClassIds.add(o.getTeachingClassId());
                    }
                });


                List<TeachingClass> collect1 = teachingClassList.stream().filter(p -> !teachingClassIds.contains(p.getTeachingClassId())).collect(Collectors.toList());


                if (CollUtil.isNotEmpty(collect1)) {
                    collect1.forEach(o -> {
                        o.setState(1);
                    });
                    teachingClassService.saveOrUpdateBatch(collect1);
                }


                List<ParameterSetting> parameterSettingList = parameterSettingMapper.selectList(new LambdaQueryWrapper<ParameterSetting>()
                        .eq(ParameterSetting::getTaskId, taskId)
                        .eq(ParameterSetting::getGradeId, gradeId)
                        .eq(ParameterSetting::getCourseId, courseId)
                        .eq(ParameterSetting::getFlag, 2)
                        .eq(ParameterSetting::getDeleted, Deleted.NOT.getCode()));


                List<Long> parameterSettingId = new ArrayList<>();
                parameterSettingList.forEach(o -> {
                    if (ObjUtil.isNull(o.getTeacherId())) {
                        parameterSettingId.add(o.getId());
                    }
                });
                List<ParameterSetting> collect3 = parameterSettingList.stream().filter(p -> !parameterSettingId.contains(p.getId())).collect(Collectors.toList());

                if (CollUtil.isNotEmpty(collect3)) {
                    collect3.forEach(o -> {
                        o.setState(1);
                    });
                    parameterSettingService.saveOrUpdateBatch(collect3);
                }


                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .eq(TeachingClass::getTaskId, taskId)
                        .eq(TeachingClass::getGradeId, gradeId)
                        .eq(TeachingClass::getCourseId, courseId)
                        .eq(TeachingClass::getFlag, 2)
                        .isNull(TeachingClass::getUniqueShiftSign)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getIsEnable, isEnable));

                parameterSettingMapper.update(null, new LambdaUpdateWrapper<ParameterSetting>()
                        .eq(ParameterSetting::getTaskId, taskId)
                        .eq(ParameterSetting::getGradeId, gradeId)
                        .eq(ParameterSetting::getCourseId, courseId)
                        .eq(ParameterSetting::getFlag, 2)
                        .eq(ParameterSetting::getDeleted, Deleted.NOT.getCode())
                        .set(ParameterSetting::getIsEnable, isEnable));
            } else {
                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .eq(TeachingClass::getTaskId, taskId)
                        .eq(TeachingClass::getGradeId, gradeId)
                        .eq(TeachingClass::getCourseId, courseId)
                        .eq(TeachingClass::getFlag, 2)
                        .isNull(TeachingClass::getUniqueShiftSign)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getState, 1)
                        .set(TeachingClass::getIsEnable, isEnable));

                parameterSettingMapper.update(null, new LambdaUpdateWrapper<ParameterSetting>()
                        .eq(ParameterSetting::getTaskId, taskId)
                        .eq(ParameterSetting::getGradeId, gradeId)
                        .eq(ParameterSetting::getCourseId, courseId)
                        .eq(ParameterSetting::getFlag, 2)
                        .eq(ParameterSetting::getDeleted, Deleted.NOT.getCode())
                        .set(ParameterSetting::getState, 1)
                        .set(ParameterSetting::getIsEnable, isEnable));
            }

        }
        return "课程状态已修改";
    }

    @Override
    public String updateBatchTeaching(Integer taskId, List<Long> teachingClassIds, List<Long> teacherIds, Integer hourtype) {

        List<TeachingClassTeacher> teachingClassTeacherList = teachingClassTeacherMapper.selectList(new LambdaQueryWrapper<TeachingClassTeacher>()
                .in(TeachingClassTeacher::getTeachingClassId, teachingClassIds)
                .eq(TeachingClassTeacher::getDeleted, Deleted.NOT.getCode()));

        //删除之前的教师设置
        if (CollUtil.isNotEmpty(teachingClassTeacherList)) {
            List<Long> deletedTeachingClassIds = teachingClassTeacherList.stream().map(TeachingClassTeacher::getTeachingClassId)
                    .distinct().collect(Collectors.toList());

            if (ObjUtil.isNull(hourtype)) {
                teachingClassTeacherService.lambdaUpdate().in(TeachingClassTeacher::getTeachingClassId, deletedTeachingClassIds).remove();
            } else {

                teachingClassTeacherService.lambdaUpdate().in(TeachingClassTeacher::getTeachingClassId, deletedTeachingClassIds)
                        .eq(ObjUtil.isNotNull(hourtype), TeachingClassTeacher::getTeacherType, hourtype)
                        .remove();
            }
        }

        List<TeachingClassWeek> teachingClassWeekList = teachingClassWeekMapper
                .selectList(new LambdaQueryWrapper<TeachingClassWeek>()
                        .in(TeachingClassWeek::getTeachingClassId, teachingClassIds)
                        .eq(TeachingClassWeek::getDeleted, Deleted.NOT.getCode()));


        List<TeachingClass> teachingClassList = teachingClassMapper.selectList(new LambdaQueryWrapper<TeachingClass>()
                .eq(TeachingClass::getTaskId, taskId)
                .in(TeachingClass::getTeachingClassId, teachingClassIds).eq(TeachingClass::getDeleted, Deleted.NOT.getCode()));


        List<Teacher> teacherList = teacherMapper.selectList(new LambdaQueryWrapper<Teacher>().in(Teacher::getTeacherId, teacherIds)
                .eq(Teacher::getDeleted, Deleted.NOT.getCode()));


        List<TeachingClassTeacher> teachingClassTeachers = new ArrayList<>();


        if (CollUtil.isNotEmpty(teachingClassList)) {

            if (ObjUtil.isNull(hourtype)) {
                teachingClassIds.forEach(o -> {
                    List<TeachingClassWeek> collect = teachingClassWeekList.stream().filter(p -> p.getTeachingClassId().equals(o)).collect(Collectors.toList());
                    collect.forEach(b -> {
                        teacherList.forEach(t -> {
                            TeachingClassTeacher teachingClassTeacher = new TeachingClassTeacher();
                            teachingClassTeacher.setTeachingClassId(o);
                            teachingClassTeacher.setTeacherId(t.getTeacherId());
                            teachingClassTeacher.setTeacherName(t.getTeacherName());
                            teachingClassTeacher.setTeacherType(b.getHourType());
                            teachingClassTeachers.add(teachingClassTeacher);
                        });
                    });

                });
            } else {
                teachingClassIds.forEach(o -> {
                    teacherList.forEach(t -> {
                        TeachingClassTeacher teachingClassTeacher = new TeachingClassTeacher();
                        teachingClassTeacher.setTeachingClassId(o);
                        teachingClassTeacher.setTeacherId(t.getTeacherId());
                        teachingClassTeacher.setTeacherName(t.getTeacherName());
                        teachingClassTeacher.setTeacherType(hourtype);
                        teachingClassTeachers.add(teachingClassTeacher);
                    });
                });
            }
        }

        teachingClassTeacherService.saveBatch(teachingClassTeachers);
        teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                .in(TeachingClass::getTeachingClassId, teachingClassIds).set(TeachingClass::getState, 0));


        List<Long> teachingClassIdes = teachingClassList.stream().filter(p -> p.getFlag().equals(2)).map(TeachingClass::getTeachingClassId).collect(Collectors.toList());


        if(CollUtil.isNotEmpty(teachingClassIdes)){
            teachingClassIds.removeAll(teachingClassIdes);

            teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                    .in(TeachingClass::getTeachingClassId, teachingClassIdes).set(TeachingClass::getState, 1));
        }


        if(CollUtil.isNotEmpty(teachingClassIds)){

            List<TeachingClassWeek> teachingClassWeekList1 = teachingClassWeekMapper.selectList(new LambdaQueryWrapper<TeachingClassWeek>().in(TeachingClassWeek::getTeachingClassId, teachingClassIds)
                    .eq(TeachingClassWeek::getDeleted, Deleted.NOT.getCode()));
            List<TeachingClassTeacher> teachingClassTeacherList1 = teachingClassTeacherMapper.selectList(new LambdaQueryWrapper<TeachingClassTeacher>().in(TeachingClassTeacher::getTeachingClassId, teachingClassIds)
                    .eq(TeachingClassTeacher::getDeleted, Deleted.NOT.getCode()));


            List<Long> updateTeachingClassIds = new ArrayList<>();
            teachingClassIds.forEach(o->{
                List<TeachingClassWeek> teachingClassWeekList2 = teachingClassWeekList1.stream().filter(p->p.getTeachingClassId().equals(o)).collect(Collectors.toList());

                List<TeachingClassTeacher> teachingClassTeacherList2 = teachingClassTeacherList1.stream().filter(p->p.getTeachingClassId().equals(o)).collect(Collectors.toList());
                Boolean flag = false;
                if (CollUtil.isNotEmpty(teachingClassWeekList2)) {
                    List<TeachingClassWeek> collect1 = teachingClassWeekList2.stream().filter(p -> ObjUtil.isNull(p.getRoomType())).distinct().collect(Collectors.toList());
                    if (!CollUtil.isEmpty(collect1)) {
                        flag = true;
                    }
                }

                if(CollUtil.isEmpty(teachingClassTeacherList2)){
                    flag = true;
                }

                if(CollUtil.isNotEmpty(teachingClassTeacherList2)){
                    Map<Integer, List<TeachingClassTeacher>> collect2 = teachingClassTeacherList2.stream().collect(Collectors.groupingBy(TeachingClassTeacher::getTeacherType));
                    List<Integer> collect1 = teachingClassWeekList2.stream().map(TeachingClassWeek::getHourType).distinct().collect(Collectors.toList());

                    if(collect1.size()!=collect2.size()){
                        flag = true;
                    }
                }
                if(!flag){
                    updateTeachingClassIds.add(o);
                }
            });

            if(CollUtil.isNotEmpty(updateTeachingClassIds)){
                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .in(TeachingClass::getTeachingClassId, updateTeachingClassIds)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getState, 1));
            }
        }


        return "教师已经批量设置";


    }

    @Override
    public String updateIsEnable(Integer taskId, Long teachingClassId, Integer isEnable) {

            if (isEnable == 0 || isEnable == 6) {

                TeachingClass teachingClass = teachingClassMapper.selectOne(new LambdaQueryWrapper<TeachingClass>().eq(TeachingClass::getTaskId, taskId).eq(TeachingClass::getTeachingClassId, teachingClassId));
                if(teachingClass.getFlag().equals(1)){
                    teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                            .eq(TeachingClass::getTeachingClassId, teachingClassId)
                            .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                            .set(TeachingClass::getState, 0));

                    List<TeachingClassWeek> teachingClassWeekList = teachingClassWeekMapper.selectList(new LambdaQueryWrapper<TeachingClassWeek>()
                            .eq(TeachingClassWeek::getTeachingClassId, teachingClassId).eq(TeachingClassWeek::getDeleted, Deleted.NOT.getCode()));


                    List<TeachingClassTeacher> teachingClassTeacherList = teachingClassTeacherMapper.selectList(new LambdaQueryWrapper<TeachingClassTeacher>()
                            .eq(TeachingClassTeacher::getTeachingClassId, teachingClassId).eq(TeachingClassTeacher::getDeleted, Deleted.NOT.getCode()));

                    Boolean flag = false;
                    if (CollUtil.isNotEmpty(teachingClassWeekList)) {
                        List<TeachingClassWeek> collect = teachingClassWeekList.stream().filter(p -> ObjUtil.isNull(p.getRoomType())).distinct().collect(Collectors.toList());
                        if (CollUtil.isNotEmpty(collect)) {
                            flag = true;
                        }
                    }

                    if (CollUtil.isEmpty(teachingClassTeacherList)) {
                        flag = true;
                    }

                    if (CollUtil.isNotEmpty(teachingClassTeacherList)) {
                        Map<Integer, List<TeachingClassTeacher>> collect = teachingClassTeacherList.stream().collect(Collectors.groupingBy(TeachingClassTeacher::getTeacherType));
                        List<Integer> collect1 = teachingClassWeekList.stream().map(TeachingClassWeek::getHourType).distinct().collect(Collectors.toList());

                        if (collect1.size() != collect.size()) {
                            flag = true;
                        }
                    }
                    if (!flag) {
                        teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                                .eq(TeachingClass::getTeachingClassId, teachingClassId)
                                .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                                .set(TeachingClass::getState, 1));
                    }

                }else{

                    teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                            .eq(TeachingClass::getTeachingClassId, teachingClassId)
                            .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                            .set(TeachingClass::getState, 0));

                    List<TeachingClassTeacher> teachingClassTeacherList = teachingClassTeacherMapper.selectList(new LambdaQueryWrapper<TeachingClassTeacher>()
                            .eq(TeachingClassTeacher::getTeachingClassId, teachingClassId).eq(TeachingClassTeacher::getDeleted, Deleted.NOT.getCode()));

                    if(CollUtil.isNotEmpty(teachingClassTeacherList)){
                        teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                                .eq(TeachingClass::getTeachingClassId, teachingClassId)
                                .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                                .set(TeachingClass::getState, 1));
                    }
                }

                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .eq(TeachingClass::getTeachingClassId, teachingClassId)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getIsEnable, isEnable));
            } else {
                teachingClassMapper.update(null, new LambdaUpdateWrapper<TeachingClass>()
                        .eq(TeachingClass::getTeachingClassId, teachingClassId)
                        .eq(TeachingClass::getDeleted, Deleted.NOT.getCode())
                        .set(TeachingClass::getState, 1)
                        .set(TeachingClass::getIsEnable, isEnable));
            }


            return "是否启用已修改";
        }

}
